<template>
  <el-card>
    <template #header>
      <div class="card-header">
        <span>实名认证</span>
      </div>
    </template>
    <div class="auth-container">
      <p class="title">
        实名认证后才能添加就诊人，正常进行挂号，为了不影响后续步骤，建议提前使命认证
      </p>
      <el-descriptions :column="1" border v-if="user && user.authStatus == 1">
        <el-descriptions-item :width="10" label="用户姓名">{{ user.name }}</el-descriptions-item>
        <el-descriptions-item :width="10" label="证件类型">{{ dictList.filter(item => (item.value + '') == user.certificatesType)[0]?.name }}</el-descriptions-item>
        <el-descriptions-item :width="10" label="证件号码">{{
          user.certificatesNo
        }}</el-descriptions-item>
      </el-descriptions>
      <el-form :model="userAuthVo" v-else>
        <el-form-item label="用户姓名" prop="name">
          <el-input placeholder="请输入用户名" v-model="userAuthVo.name" />
        </el-form-item>
        <el-form-item label="证件类型" prop="certificatesType">
          <el-select clearable placeholder="选择证件类型" v-model="userAuthVo.certificatesType">
            <el-option
              :label="item.name"
              v-for="item in dictList"
              :key="item.id"
              :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件号码" prop="name">
          <el-input placeholder="请输入证件号码" v-model="userAuthVo.certificatesNo" />
        </el-form-item>
        <el-form-item label="上传证件" prop="name"> </el-form-item>
        <div class="btn-div">
          <el-button type="primary" @click="submit">提交</el-button>
          <el-button>重写</el-button>
        </div>
      </el-form>
    </div>
  </el-card>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { reqGetUserInfo, reqAuth } from '@/api/user'
import { AuthUser, UserAuthInterface, Dict } from '@/api/user/type'
import { reqGetDictByDictCode } from '@/api/user'

onMounted(() => {
  initUserData()
})

let userAuthVo = ref({} as UserAuthInterface)
let user = ref({} as AuthUser)
let dictList = ref([] as Dict[])

const initUserData = async () => {
  const { data } = await reqGetUserInfo()
  user.value = data
  // 获取证件类型
  const { data: result } = await reqGetDictByDictCode('CertificatesType')
  dictList.value = result
}
// 提交
const submit = async () => {
  const data = await reqAuth(userAuthVo.value)
  console.log(data)
}
</script>

<style lang="scss" scoped>
.auth-container {
  color: #7f7f7f;
  .title {
    text-align: center;
    margin-bottom: 20px;
    font-size: 15px;
  }
  .el-form {
    width: 500px;
    margin: 0 auto;
  }
}
</style>
